package com.example.mapper;

import com.example.entity.OrganizationActivity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrganizationActivityMapper {
    void insert(OrganizationActivity activity);
    void deleteById(Long id);
    void updateById(OrganizationActivity activity);
    OrganizationActivity selectById(Long id);
    List<OrganizationActivity> selectAll(OrganizationActivity activity);

    // com.example.mapper.OrganizationActivityMapper.java
    @Update("UPDATE organization_activity " +
            "SET status = 2 " +  // 2-进行中
            "WHERE status = 1 " + // 1-未开始
            "AND start_time <= #{now} " +
            "AND end_time > #{now}")
    int updateStatusToInProgress(LocalDateTime now);

    @Update("UPDATE organization_activity " +
            "SET status = 3 " +  // 3-已结束
            "WHERE status = 2 " + // 2-进行中
            "AND end_time <= #{now}")
    int updateStatusToFinished(LocalDateTime now);


    /**
     * 增加活动当前参与人数
     */
    int incrementParticipants(Long activityId);

    /**
     * 减少活动当前参与人数
     */
    int decrementParticipants(Long activityId);

}
